import { createRouter, createWebHistory } from 'vue-router'
import { ElMessage } from "element-plus";
import Login from '../views/Login.vue'
import Page from '../views/Page.vue'
import BackManagement from '../views/BackManagement.vue'
import Opera from "../components/Opera.vue"
import Handicraft from "../components/Handicraft.vue"
import Music from "../components/Music.vue"
import Dance from '../components/Dance.vue';
import Artist from '../components/Artist.vue';
import Statistics from '../components/Statistics.vue';

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // 登录
    {
      path: '/login',
      name: 'Login',
      component: Login,
    },
    // 首页
    {
      path: '/page',
      name: 'Page',
      component: Page,
    },
    // 后台管理
    {
      path: '/backmanagement',
      name: 'BackManagement',
      component: BackManagement,
      children:[
        {
          path: 'opera',
          name: 'Opera',
          component: Opera,
        },
        {
          path:"handicraft",
          name: 'Handicraft',
          component: Handicraft,
        },
        {
          path:"music",
          name: 'Music',
          component: Music,
        },
        {
          path:"dance",
          name: 'dance',
          component: Dance,
        },
        {
          path:"artist",
          name: 'Artist',
          component: Artist,
        },
        {
          path:"statistics",
          name: 'Statistics',
          component:Statistics,
        },
      ]
    },
  ],
})


// //添加路由守卫（前置守卫）
// router.beforeEach((to,from,next)=>{
//   let islogin=localStorage.getItem('token')?true:false
//   if(to.path==="/login"){
//     next()//继续放行
//   }else if(islogin){
//     next()
//   }else if(to.path === "/BackManagement"){
//     ElMessage({
//       message: '警告：你没有登录,请登录',
//       type: 'warning',
//       })
//     next({path:"/login"})
//   }
   
// })

export default router
